<?php

namespace App\Http\Controllers\Admin\System;

use App\Http\Controllers\AdminController;
use App\Models\System\Config;
use Illuminate\Http\Request;

class ConfigController extends AdminController
{
    public function data(Request $request)
    {
        $request->validate(['siteKey' => 'required|string']);
        return $this->succeed(Config::getPluginSet($request->get('siteKey')));
    }

    public function update(Request $request)
    {
        $request->validate([
            'siteKey' => ['required','string'],
            'formData' => ['required','array']
        ]);
        $siteKey = $request->get('siteKey');
        $data = match ($siteKey) {
            'website' => $request->only(['webname','title','keywords','description','copyright']),
            default => $request->get('value'),
        };
        return Config::updatePluginSet($siteKey, $data) ? $this->succeed() : $this->error();
    }

}
